#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "symbol.h"

Table *table_global;
int register_cnt;

bool isInTable(char *name, Table *t) {
    for (int i=0; i<t->length; i++) {
        if (strcmp(name, t->list[i]->name) == 0)
            return 1;
    }
    return 0;
}

Ident *findItem(char *name, Table *t) {
    for (int i=0; i<t->length; i++) {
        if (strcmp(name, t->list[i]->name) == 0)
            return t->list[i];
    }
    return NULL;
}

void insertItem(Ident *ident, Table *t) {
    t->list[t->length++] = ident;
}

void printTable(Table *t) {
    for (int i=0; i<t->length; i++) {
        printf("Table[%d]:\n", i);
        printf("name: %s\n", t->list[i]->name);
        printf("type: %s\n", t->list[i]->type);
        printf("def: %d\n", t->list[i]->def);
        printf("address: %d\n", t->list[i]->address);
        printf("value: %d\n", t->list[i]->value);
        printf("\n");
    }
}
